//
//  MovieDetailViewController.m
//  MansApp
//
//  Created by lanou3g on 15/7/13.
//  Copyright (c) 2015年 ACH. All rights reserved.
//

#import "MovieDetailViewController.h"
#import "CExpandHeader.h"
@interface MovieDetailViewController ()<UIWebViewDelegate>
@property (nonatomic,strong) UIWebView *MyWebView;
@property (nonatomic,assign) BOOL isLoadingFinished;
@property (nonatomic,strong) NSString *string;
@property (nonatomic,strong) NSString *ApendString;

@property (nonatomic,copy)   NSString *body;
@property (nonatomic,copy)   NSString *cssUrl;
@property (nonatomic,strong) NSData *data;

@property (nonatomic,strong) CExpandHeader *header;
@end

@implementation MovieDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = self.titleString;
    NSString *Url = [NSString stringWithFormat:@"%@%@",kMovieDetailUrl,_idString];
    
    self.MyWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 44 - 64)];
    
    [LORequestManger GET:Url success:^(id response) {
        self.body = response[@"body"];
        self.cssUrl = [response[@"css"] lastObject];
        self.data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_cssUrl]];
        
        _data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_cssUrl]];
        NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSFileManager *manager = [NSFileManager defaultManager];
        
        path = [path stringByAppendingPathComponent:@"css2.css"];
        
        [manager createFileAtPath:path contents:nil attributes:nil];
        [_data writeToFile:path options:NSUTF8StringEncoding error:nil];
        
        NSLog( @"image === %@",_pinjieUrl);
        NSString *string = [NSString stringWithFormat:@"file://%@",path];
        if (self.temp == 1000) {
            UIImageView *headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kP6Height(250))];
            NSURL *url2 = [NSURL URLWithString:_pinjieUrl];
            [headerImageView sd_setImageWithURL:url2];
            NSLog(@"===== %@",headerImageView.image);
            self.header = [CExpandHeader expandWithScrollView:_MyWebView.scrollView expandView:headerImageView];
            self.body = [self.body stringByReplacingOccurrencesOfString:@"<div class=\"img-place-holder\">" withString:@""];
            string  = [NSString stringWithFormat:@"%@<link rel=\"stylesheet\" href=\"%@\">",_body,string];
        }
        else
        {
            string  = [NSString stringWithFormat:@"%@<link rel=\"stylesheet\" href=\"%@\">",_body,string];
        }
        
        [self.MyWebView loadHTMLString:string baseURL:nil];

        
        //添加webview
        [self.view addSubview:self.MyWebView];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}


@end
